(function (_super) {
    var CONFIG = {
        "1v1": {
            "1" : 235,
            "2" : 860
        },
        "2v2" : {
            "1" : 40,
            "2" : 320,
            "3" : 760,
            "4" : 1050
        }
    };

    function Player(type, seatId) {
        Player.super(this);
        
        this.type = type;
        this.seatId = seatId;
        this.role = null;

        this.init();
    }
    Laya.class(Player, "Com.Waiting.Player", _super);
    var _proto = Player.prototype;
    _proto.destroy = function () {
        _super.prototype.destroy.call(this, true);

        this.type = null;
        this.seatId = null;
        this.role = null;
    }

    _proto.init = function () {
        this.alpha = 0;
        this.x = CONFIG[this.type][this.seatId];
        this.y = -50;

        var mask = new Laya.Sprite();
            mask.loadImage("res/public/avatar_mask.png", 0, 0, this.avatar.width, this.avatar.height);
        this.avatar.mask = mask;

        this.userExit();
    }
    _proto.userEnter = function (data) {
        this.role && this.role.destroy(true);
        this.role = null;
        
        var role = utils.createSkeleton(ROLE_NORMAL_SKIN_PATH + data.roleId);
            role.pos(this.roleWrap.width / 2, this.roleWrap.height / 2);
            role.scale(0.6, 0.6);
            role.play(0, true);
            
        this.avatar.skin = data.avatar == "" ? USER_DEFAULT_AVATAR : data.avatar;
        
        this.roleName.text = data.roleName;
        this.level.text = "lv:" + data.lvl;
        this.userName.text = utils.cutStr(data.userName, 10);

        this.me.visible = (data.userId == userId);

        this.role = role;
        this.roleWrap.addChild(role);

        this.waitingAni.stop();
        this.waiting.visible = false;

        this.playerAni.play(0, true);
        this.player.visible = true;
    }
    _proto.userExit = function () {
        this.playerAni.stop();
        this.player.visible = false;
                
        this.waitingAni.play(0, true);
        this.waiting.visible = true;
    }

    _proto.update = function (mode, data) {
        switch(mode){
            case "exit":
                this.userExit();
                break;
            case "enter":
                this.userEnter(data);
                break;
        }
    }
    _proto.enter = function () {
        Laya.Tween.to(this, {y : 25, alpha : 1}, 300, Laya.Ease.bounceOut, null, Math.random() * 50 + 50);
    }
})(ui.Waiting.PlayerUI);